XML Document with Internal DTD


An internal DTD (Document Type Definition) can be used to provide declarations about elements that are not handled in external DTDs. In the early stages of application development, it's sometimes convenient to handle declarations in an internal DTD. After testing prototypes of markup, a final version of the declarations can be transferred to an external DTD. In some cases, authors might want to use both an internal DTD and an external DTD. When an internal DTD declares some item that is also declared in the external DTD, the internal declaration supersedes the external declaration. An internal DTD is not often used, however, because it adds to the document's size and must be included in every document instance.

An XML document begins with a processing instruction that tells the XML parser which version of XML is being used. Processing instructions always start with <? and end with ?>:

<?xml version="1.0"?>

Next a document type is declared, which begins with

<!DOCTYPE string [

and ends with

]>

where string (a Name) is the internal identifier for the declaration and essentially names the document element type to which the declaration applies.

Next, elements associated with the document type are defined. These elements contain markup declarations which consist of keyword assignments for tags and their associated parameters.

Assignments follow the basic structure:

<!ASSIGNMENT assignment_name associated_parameter(s)>

XML supports four assignment types, ELEMENT, ATTLIST, ENTITY, and NOTATION.

The document type and the element definitions are officially called a Document Type Definition (DTD). An sample XML document with an internal DTD is given below.

<?xml version="1.0"?><!DOCTYPE menu [
<!ENTITY  restop "Skipper Jack's Seafood Restaurant and Raw Bar" ><!ELEMENT menu (rname,(item,extend?)*) ><!ATTLIST menu
          date   CDATA    #REQUIRED
          ref    CDATA    #IMPLIED
          rest   CDATA    #FIXED     "&restop;" ><!ELEMENT item (desc, price, graphic?) ><!ATTLIST item
          type (appetizer|entree|dessert|drink)  "entree" >
<!ELEMENT desc (#PCDATA | emph)* ><!ELEMENT price (#PCDATA)* ><!ATTLIST price
          units CDATA  #REQUIRED ><!ELEMENT graphic EMPTY ><!ATTLIST graphic
          gtype CDATA  #REQUIRED
          src   CDATA  #REQUIRED >]><menu date="April 1, 2000">   <rname>&restop;</rname>          <!-- ENTITY USED HERE -->   <item type="appetizer" >      <desc>The Skipper's Jumbo Shrimp Cocktail</desc>      <price units="usd">7.95</price>      <graphic gtype="gif" src="http://www.skipperjacks.com/menu/jumboshrimp.gif"/>   </item>   <item type="appetizer" >      <desc>Oysters Rockefeller</desc>      <price units="usd">8.95</price>      <graphic gtype="jpg" src="http://www.skipperjacks.com/menu/oystersrock.jpg"/>   </item></menu>

Copyright 2000 Extensibility, Inc.

Suite 250, 200 Franklin Street, Chapel Hill, North Carolina 27516